package pruebas.inputMask;



import general.TestCore;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.Test;

import constants.ConfigurationConstants;
import constants.DataProviderConstants;
import dataprovider.DataProviderArguments;

public class InputMask2 extends TestCore{

	@Test(dataProviderClass = dataprovider.DataProviderFactory.class, dataProvider = ConfigurationConstants.DP_FACTORY)
	@DataProviderArguments(ConfigurationConstants.ESCENARIO
			 + ConfigurationConstants.EQUALS
			 + DataProviderConstants.HOJA_12)
	public void testInputMaskValidationDate(String param1, String param2, String param3) {
		
		
		selenium.open("/showcase/");
		driver.manage().window().maximize();
		
		WebElement boton = driver.findElement(By.id("SubMenu-Input"));
		boton.click();
		selenium.waitForPageToLoad("30000");

		WebElement boton1 = driver.findElement(By.xpath("//*[@id='MENUSIDEindent']/div[3]/a[10]"));
		boton1.click();
		selenium.waitForPageToLoad("30000");
		
		WebElement elemento=null;
		
		elemento = driver.findElement(By.id("j_idt88:date"));
		elemento.click();
		elemento.sendKeys((Integer.valueOf(param1)<10 ? "0"+param1:param1));
		elemento.sendKeys((Integer.valueOf(param2)<10 ? "0"+param2:param2));
		elemento.sendKeys(param3);
		
		elemento = driver.findElement(By.id("j_idt88:j_idt97"));
		elemento.click();
		selenium.waitForPageToLoad("30000");
		
		WebDriverWait webDriverWait = new WebDriverWait(driver, 3);
		webDriverWait.until(ExpectedConditions.elementToBeClickable(
				By.xpath("//*[@id='j_idt88:display']/tbody/tr[1]/td[2]")));;

		//se valida la seleccion exitosa
		if(selenium.isElementPresent("//*[@id='j_idt88:display']/tbody/tr[1]/td[2]")){
			elemento = driver.findElement(By.xpath("//*[@id='j_idt88:display']/tbody/tr[1]/td[2]"));
		}else{
			elemento = null;
		}

		Assert.assertNotNull(elemento);
		Assert.assertEquals(elemento.getText(), 
				(Integer.valueOf(param1)<10 ? "0"+param1:param1)+"/"+(Integer.valueOf(param2)<10 ? "0"+param2:param2)+"/"+param3);
	}

}
